import React, { Component } from 'react';
import './Tiplist.scss'
import { index_goodlist } from '../../utils/api'
import { withRouter } from 'react-router-dom'

class Tiplist extends Component {
    constructor(props) {
        super(props);
        this.state = {
            list: []
        }
    }
    componentDidMount() {
        index_goodlist().then((res) => {
            console.log(res.data.list);
            this.setState(
                this.state.list = res.data.list
            )
        })
    }

    togoodinfo(id) {
        this.props.history.push({ pathname: '/goodinfo', state: { id } })
    }
    render() {
        return (
            <div className='tiplist'>
                <div className="time">
                    <div>今日值得买<span className='shi'>00:40:10</span><span className='shu'>后结束</span></div>
                    <div>MORE</div>
                </div>
                <div className="count">
                    {
                        this.state.list.map((item, index) => {
                            return (
                                <div className="item" key={index} onClick={() => { this.togoodinfo(item.id) }}>
                                    <img src={item.pic} alt="" />
                                    <div className="text">
                                        <p>{item.name}</p>
                                        <span className='price'>原价￥430</span>
                                        <p className='pri'><span className='qiang'>抢购价 ￥</span>{parseInt(item.salesPrice.value)}</p>
                                    </div>
                                </div>
                            )
                        })
                    }
                </div>
            </div>
        );
    }
}

export default withRouter(Tiplist);